<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<h1 id="msg">hello stock!</h1>

<body>

<script>
    var ws = new WebSocket('ws://localhost:8082/webSocket/zhangs');
    ws.onopen = function () {
        ws.send('生产者：生产数据')
    }
    ws.onmessage = function (res) {
        let element = document.getElementById("msg");
        element.innerHTML = res.data;
        console.log('消费者消费数据：'+res.data);
    }
    ws.onclose = function () {
        console.log('生产者：关闭');
    }
    ws.onerror = function () {undefined
        console.log('链接发生错误');
    }
</script>
</body>
</html>